function HashTable() {
    this.table = new Array(137);
    this.value = new Array(137);
    this.hash = hash;
    this.showDistro = showDistro;
    this.put = put;
    this.get = get;
}

const hash = function (key) {
    const H = 37;
    if (typeof (key) === "number") {
        return key % this.table.length;
    }
    else if (typeof (key) === "string") {
        let charCodeSum = 0;
        for (let i = 0; i < key.length; i++) {
            charCodeSum += H * charCodeSum + key.charCodeAt(i);
        }
        return charCodeSum % this.table.length;
    }
    return null;
}

const put = function (key, value) {
    let hashNumber = this.hash(key);
    while(this.table[hashNumber] !== undefined) {
        hashNumber = hashNumber + 1;
        if(hashNumber >= this.table.length) {
            return null;
        }
    }
    this.table[hashNumber] = key;
    this.value[hashNumber] = value;
}

const get = function (key) {
    let hashNumber = this.hash(key);
    while(this.table[hashNumber] !== key) {
        hashNumber = hashNumber + 1;
        if(hashNumber >= this.table.length) {
            return null;
        }
    }
    return this.value[hashNumber];
}

const showDistro = function () {
    let stringLine = "";
    this.table.forEach((tableItem, index) => {
        if(tableItem !== undefined) {
            stringLine += tableItem + ": " + this.value[index] + "=>"
        }
    })
    console.log(stringLine);
}

const hashTable = new HashTable();
hashTable.put("asf", "test1");
hashTable.put("asf", "test2");
hashTable.put("asf", "test3");
hashTable.showDistro();